package priv.pront.code.national.acwing.dp.bags;

import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-09 12:34
 */
public class Acwing5_多重背包II {

    static int n, m;
    static int[] dp, v, w, s;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt(); m = scanner.nextInt();
        dp = new int[m + 1];
        v = new int[20000];
        w = new int[20000];
        s = new int[20000];
        int cnt = 0;
        for(int i = 1; i <= n; i++){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int s = scanner.nextInt();
            int k = 1;
            while(k <= s){
                cnt++;
                v[cnt] = k * a;
                w[cnt] = k * b;
                s -= k;
                k *= 2;
            }
            if(s > 0){
                cnt++;
                v[cnt] = s * a;
                w[cnt] = s * b;
            }
        }
        n = cnt;
        for(int i = 1; i <= n; i++){
            for(int j = m; j >= v[i]; j--){
                dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        System.out.println(dp[m]);
    }
}
